﻿using System.Data.Entity.ModelConfiguration;

using NeGroid.ChampionshipManager.Core;

namespace NeGroid.ChampionshipManager.Persistance.Mappings
{
	public class GameInfoMap : EntityTypeConfiguration<GameInfo>
	{
		public GameInfoMap()
		{
			HasKey(t => t.GameId);
			Ignore(t => t.Id);

			Property(t => t.Timestamp)
				.IsConcurrencyToken();

			HasRequired(t => t.Game)
				.WithOptional(t => t.GameResult);
			HasOptional(t => t.Refery)
				.WithMany(t => t.Games)
				.HasForeignKey(t => t.ReferyId);
			HasMany(t => t.Goals)
				.WithOptional(t => t.GameResult);
            HasMany(t => t.TeamHomePlayers)
                .WithMany();
            HasMany(t => t.TeamGuestPlayers)
                .WithMany();
            HasMany(t => t.Substitions)
                .WithRequired(t => t.GameInfo)
                .HasForeignKey(t => t.GameInfoId);
			
            ToTable("GameInfos");
		}
	}
}
